package net.kazed.nextaction.timer;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

/**
 * Processes timer notification.
 * @author Koert Zeilstra
 */
public class TimerProcessor extends BroadcastReceiver {

    /**
     * Constructor.
     */
    public TimerProcessor() {
      super();
   }

   @Override
    public void onReceive(Context context, Intent intent) {
      Notifier notifier = new Notifier(context);

      Bundle bundle = intent.getExtras();
      int taskId = bundle.getInt("taskId");
      long startTime = bundle.getLong("startTime");
      int durationMinutes = bundle.getInt("durationMinutes");
      String taskDescription = bundle.getString("text");
      long finishTime = startTime + durationMinutes * 60000;
      if (System.currentTimeMillis() > finishTime) {
         notifier.timerStop(taskId, taskDescription);
      } else {
         notifier.timerUpdate(taskId, startTime, durationMinutes, taskDescription);
      }
   }

}
